<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <title>Doe</title>
    <!-- 导入头部 ,统一引用那些静态资源  -->
    <link rel="stylesheet" th:href="@{~/v3/assets/css/dropzone.css}" />
    <script th:replace="/pages/tpl/head::header"></script>
</head>
<body>

<div th:replace="/pages/tpl/top::topper"></div>


<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <div class="main-container-inner">

        <div th:utext="${menuHtml}"></div>

        <div class="main-content">
            <div th:replace="/pages/tpl/bread::breader"></div>

            <div class="page-content">
                <div class="page-header">
                    <h1>
                        编辑依赖
                    </h1>
                </div>
                <!-- /.page-header -->

                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <div class="col-xs-12">

                                <h4 class="smaller green" id="lblTitle"></h4>

                                <textarea class="form-control" id="txtParams" rows="20"
                                          placeholder=""></textarea>
                                    <span class="smaller-20 lighter green">编辑pom文件后，或可以在系统管理->系统配置->重启生效.</span>

                            </div>
                        </div>


                        <div class="row">
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-success" id="bootbox-regular" onclick="doSave();">保存POM文件</button>
                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn btn-info" type="button" onclick="doParsePom();">
                                        <i class="icon-ok bigger-110"></i>
                                        解析POM文件
                                    </button>
                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn btn-info" type="button" onclick="doReload();">
                                        <i class="icon-ok bigger-110"></i>
                                        重新加载JAR
                                    </button>
                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset" onclick="doClear();">
                                        <i class="icon-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>

                        </div>


                    </div><!-- /.col -->
                </div>

                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
        <!-- /.main-content -->

    </div>
    <!-- /.main-container-inner -->

    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>
<!-- /.main-container -->
<script type="text/javascript">
    if("ontouchend" in document) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>

<script th:src="@{~/v3/assets/js/fuelux/fuelux.wizard.min.js}"></script>
<script th:src="@{~/v3/assets/js/bootbox.min.js}"></script>
<script th:replace="/pages/tpl/foot::footer"></script>

<script type="text/javascript">

    var jobRef = ""; // 定时任务引用

    function doClear() {

        $("#txtParams").val("");

    }
    function doRequest(requestId) {

        var param = {"requestId": requestId};

        Nora.Ajax("/doe/pom/doMsg", param, function (data) {
            if (data.success) {
                // on success
                $("#txtParams").scrollTop(500000);
                if (data.code == 1) {
                    // continue get message
                    var message = data.data;
                    $("#txtParams").val($("#txtParams").val() + "\n" + message);


                } else if (data.code == 2) {
                    // complete
                    var message = data.data;
                    // 替换所有的换行符
                    $("#txtParams").val($("#txtParams").val() + "\n" + message);
                    $("#lblTitle").text(data.msg);

                    clearInterval(jobRef);

                } else {

                    // 阻止定时刷新
                    clearInterval(jobRef);
                }

            } else {
                // on fail
                // 阻止定时刷新
                clearInterval(jobRef);
                bootbox.alert(data.msg);
            }

        }, function (data) {
            // on fail
            // 阻止定时刷新
            clearInterval(jobRef);
            bootbox.alert(data.msg);
        });
    }
    function doParsePom() {

        var param = {};

        Nora.Ajax("/doe/pom/doReparse", param, function (data) {
            if (data.success) {
                // on success
                var msg = data.msg;
                $("#txtParams").val("");
                $("#lblTitle").text(msg);
                var requestId = data.data.requestId;

                getRealTimeMessage(requestId);

            } else {
                bootbox.alert(data.msg);
            }

        }, function (data) {
            // on fail
            bootbox.alert(data.msg);
        });
    }
    function getRealTimeMessage(requestId) {

        if (null == requestId || requestId.length <= 0) {
            bootbox.alert("获取不到请求ID！");
            return;
        }

        // 设置定时刷新
        jobRef = setInterval(function(){
            doRequest(requestId);
        },1000);

    }
    function doReload() {

        var param = {};
        Nora.Ajax("/doe/pom/doLoad", param, function (data) {

            bootbox.alert(data.msg);

        }, function (data) {
            bootbox.alert(data.msg);
        });
    }
    function doSave() {

        var content = $("#txtParams").val();
        if (null == content || content.length <= 0) {
            return;
        }

        var params = {"content": content};

        Nora.Ajax("/doe/pom/doOverridePomFile", params, function (data) {

            if (data.success && data.data) {

                // on success
                // $("#txtParams").val("success"); // clear
                bootbox.alert("sucuss");

            } else {
                // on fail
                bootbox.alert(null == data ? "操作失败！" : null != data.msg ? data.msg : data.remark);
            }

        }, function (data) {
            // on error
            bootbox.alert(null == data ? "操作失败！" : null != data.msg ? data.msg : data.remark);
        });

    }
    function doLoad() {

        var params = {};
        Nora.Ajax("/doe/pom/doLoadPomFile", params, function (data) {

            if (data.success && null != data.data && data.data.length > 0) {

                // on success
                $("#txtParams").val(data.data); // clear

            } else {
                // on fail
                bootbox.alert(null == data ? "操作失败！" : null != data.msg ? data.msg : data.remark);
            }

        }, function (data) {
            // on error
            bootbox.alert(null == data ? "操作失败！" : null != data.msg ? data.msg : data.remark);
        });

    }

    jQuery(function($) {

        doLoad();

    });
</script>

</body>
</html>